import type { Result } from '@/components/echarts_allocation/types'
// 资源详情
export type TResourceItem = {
  id: number | string, // id
  code: string, // 编号
  create: string, // 创建时间
  created_time: string, // 创建时间
  data_browsing_number: number, // 数据浏览次数
  data_call_number: number, // 数据调用次数
  data_download_number: number, // 数据下载次数
  data_fields_count: number, // 数据字段数量
  data_update_time: string, // 数据更新时间
  from: string, // 数据来源
  is_root: number, // 是否根节点
  name: string, // 数据名称
  production_resource: string, // 生产资源
  resource_owner: { // ****************************** 老接口 多余字段 ******************************
    address: string, // 地址
    code: string, // 编号
    created_time: string, // 创建时间
    credit_code: string, // 信用代码
    id: number | string, // id
    name: string // 名称
  }[], // 资源所属单位
  scene: string[], // 场景
  security_level: string, // 安全等级
  sync_consanguinity: boolean, // 同步关系
  update_frequency: string, // 更新频率
  update_time: string, // 更新时间
  version: number | string // 版本

  owner_org_code: any[], // 资源所属单位编号

  can_change_root: boolean, // 是否可修改成根资源
}

export type TResourceList = TResourceItem[]

// 资源关系
export interface TResourceRelationItem extends Result {
  currently: boolean,
  id: string,
  name: string,
  parent_id: string[],
  type: string,
  version: number
}

// 资源版本
export type TResourceVerItem = {
  name: string,
  resource_code: string,
  versions: {
    create_name: string,
    create_time: string,
    id: number,
    update_time: string,
    version: number
  }[]
}

function getNow(type = 'datetime') {
  const date = new Date()
  const year = date.getFullYear()
  let month: any = date.getMonth() + 1
  let day: any = date.getDate()
  let hour : any= date.getHours()
  let minute: any = date.getMinutes()
  let second: any = date.getSeconds()
  month = month < 10 ? `0${month}` : month
  day = day < 10 ? `0${day}` : day
  hour = hour < 10 ? `0${hour}` : hour
  minute = minute < 10 ? `0${minute}` : minute
  second = second < 10 ? `0${second}` : second
  const dateStr = `${year}-${month}-${day}`
  const timeStr = `${hour}:${minute}:${second}`
  if (type === 'date') {
    return dateStr
  } else if (type === 'time') {
    return timeStr
  } else {
    return `${dateStr} ${timeStr}`
  }
}

export function DefaultTResourceItem(): TResourceItem {
  // 返回 类型 TResourceItem 的默认值
  return {
    id: 0,
    code: '',
    create: '',
    created_time: '',
    data_browsing_number: 0,
    data_call_number: 0,
    data_download_number: 0,
    data_fields_count: 0,
    data_update_time: getNow('datetime'),
    from: '',
    is_root: 1,
    name: '',
    production_resource: '',
    resource_owner: [],
    scene: [],
    security_level: '',
    sync_consanguinity: false,
    update_frequency: '',
    update_time: '',
    version: 0,

    owner_org_code: [],
    can_change_root: true,
  }
}